package com.ruoyi.system.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.EmPropertiesHistoryVo;
import com.ruoyi.system.domain.bo.EmPropertiesHistoryBo;
import com.ruoyi.system.service.IEmPropertiesHistoryService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 不动产-历史
 *
 * @author ruoyi
 * @date 2024-11-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/propertiesHistory")
public class EmPropertiesHistoryController extends BaseController {

    private final IEmPropertiesHistoryService iEmPropertiesHistoryService;

    /**
     * 查询不动产-历史列表
     */
    @SaCheckPermission("system:propertiesHistory:list")
    @GetMapping("/list")
    public TableDataInfo<EmPropertiesHistoryVo> list(EmPropertiesHistoryBo bo, PageQuery pageQuery) {
        return iEmPropertiesHistoryService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出不动产-历史列表
     */
    @SaCheckPermission("system:propertiesHistory:export")
    @Log(title = "不动产-历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EmPropertiesHistoryBo bo, HttpServletResponse response) {
        List<EmPropertiesHistoryVo> list = iEmPropertiesHistoryService.queryList(bo);
        ExcelUtil.exportExcel(list, "不动产-历史", EmPropertiesHistoryVo.class, response);
    }

    /**
     * 获取不动产-历史详细信息
     *
     * @param emId 主键
     */
    @SaCheckPermission("system:propertiesHistory:query")
    @GetMapping("/{emId}")
    public R<EmPropertiesHistoryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long emId) {
        return R.ok(iEmPropertiesHistoryService.queryById(emId));
    }

    /**
     * 新增不动产-历史
     */
    @SaCheckPermission("system:propertiesHistory:add")
    @Log(title = "不动产-历史", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EmPropertiesHistoryBo bo) {
        return toAjax(iEmPropertiesHistoryService.insertByBo(bo));
    }

    /**
     * 修改不动产-历史
     */
    @SaCheckPermission("system:propertiesHistory:edit")
    @Log(title = "不动产-历史", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EmPropertiesHistoryBo bo) {
        return toAjax(iEmPropertiesHistoryService.updateByBo(bo));
    }

    /**
     * 删除不动产-历史
     *
     * @param emIds 主键串
     */
    @SaCheckPermission("system:propertiesHistory:remove")
    @Log(title = "不动产-历史", businessType = BusinessType.DELETE)
    @DeleteMapping("/{emIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] emIds) {
        return toAjax(iEmPropertiesHistoryService.deleteWithValidByIds(Arrays.asList(emIds), true));
    }
}
